package kr.hkit.powerjava.chapter25.chat;

public class QuizPrtocol {
	private static final int WAITING = 0;
	private static final int PROBLEM = 1;
	private static final int ANSWER=2;
	
	private static final int NUMPROBLEMS =3;
	
	private int state = WAITING;
	private int currentProblm = 0;
	
	private String[] problems ={"네트워크 처리 패키지는?", "자바의 최신버전은?"
			,"인터넷에서 커퓨터를 식별하는 주소는"};
	private String[] answers = {"java.io","1.7","IP 주소"};
	
	public String proceess(String theInput){
		String theOutput = null;
		
		switch(state){
			case QuizPrtocol.WAITING:
			theOutput = "퀴즈를 시작합니다(y/n)";
			state = PROBLEM;
			break;
			
			case QuizPrtocol.PROBLEM:
				if(theInput.equalsIgnoreCase("y")){
					theOutput = problems[currentProblm];
					state = ANSWER;
				}else {
					state = WAITING;
					theOutput = "quit";
				}
				
			case QuizPrtocol.ANSWER:
				if(theInput.equalsIgnoreCase(answers[currentProblm])){
					theOutput = "정답입니다. 계속하시겠습니까?(y/n)";
					state = PROBLEM;
				}else {
					theOutput = "오답입니다. 계속하시겠습니까?(y/n)";
					state=PROBLEM;
				}
			currentProblm = (currentProblm+1)% NUMPROBLEMS;
		}
		return theOutput;
	}
}
